package com.sumainfor.pc.gmio.service.impl.tenant;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.gmio.dao.tenant.TeWithdrawalEvaMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  租客退租生活费用
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-05-27 13:53
 **/
@Service
public class TeWithdrawalEvaService implements Serializable {

    @Autowired
    TeWithdrawalEvaMapper teWithdrawalEvaMapper;

    @Autowired
    ZpcMktFeign zpcMktFeign;

    /**
    * <p>
    * 查询生活费用
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    public List<Map<String,Object>> getWithArticleEvaList(Map<String,Object> params){
        List<Map<String,Object>> result = new ArrayList<>();
        JsonResult getTpTemplate = zpcMktFeign.getTpTemplate(params);
        System.out.println("接受的参数"+params);
        Map<String,Object> getTpTemplateMap = (Map<String, Object>)getTpTemplate.get("result");
        System.out.println("得到的说标准"+getTpTemplateMap);

        //电费
        Map<String,Object> powerMapOne = new HashMap<>();
        //燃气费
        Map<String,Object> gasMapOne = new HashMap<>();
        //水费
        Map<String,Object> waterMapOne = new HashMap<>();
        Map<String,Object> getWithdrMap=teWithdrawalEvaMapper.getWithdrMapOne(params);
        //水费是否（定价）不是定价  就是定额 。定额的话就是300/月，所用的水费和电费
      // if(MapUtils.getInteger(getTpTemplateMap,"IsWater")!=null&&MapUtils.getInteger(getTpTemplateMap,"IsWater")==1){
            Map<String,Object> waterMap= teWithdrawalEvaMapper.getWithdrWater(getWithdrMap);//水费
            if(waterMap==null){
                waterMapOne.put("LastMonthRead",null);
                waterMapOne.put("ThisMonthRead",null);
            }else{
                waterMapOne.put("LastMonthRead",waterMap.get("LastMonthRead"));
                waterMapOne.put("ThisMonthRead",waterMap.get("ThisMonthRead"));
            }
            waterMapOne.put("waterName","水费");
            result.add(waterMapOne);

       // }
       // 燃气费是否定价
       // if(MapUtils.getInteger(getTpTemplateMap,"IsGas")!=null&&MapUtils.getInteger(getTpTemplateMap,"IsGas")==1){
       // }else{

            Map<String,Object> gasMap = teWithdrawalEvaMapper.getWithdrGas(getWithdrMap);//燃气费
            if(gasMap ==null){
                gasMapOne.put("LastMonthRead",null);
                gasMapOne.put("ThisMonthRead",null);
            }else{
                gasMapOne.put("LastMonthRead",gasMap.get("LastMonthRead"));
                gasMapOne.put("ThisMonthRead",gasMap.get("ThisMonthRead"));
            }
            gasMapOne.put("gasName","燃气费");
            result.add(gasMapOne);

        //}

       Map<String,Object> powerMap = teWithdrawalEvaMapper.getWithdrEle(getWithdrMap);//电费
       if(powerMap==null){
            powerMapOne.put("LastMonthEleSum",null);
            powerMapOne.put("ThisMonthEleSum",null);
        }else {
           powerMapOne.put("LastMonthEleSum", powerMap.get("LastMonthEleSum"));
           powerMapOne.put("ThisMonthEleSum", powerMap.get("ThisMonthEleSum"));
       }
       powerMapOne.put("powerName", "电费");
       result.add(powerMapOne);

       return result ;
    }
}
